home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / CDTV / cdtvtools-11 / system / NoReset.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-06-24  |  3.1 KB  |  99 lines

  1. /***********************************************************************
  2. ***
  3. ***  CDTV NoReset Command 1.0 (26-SEP-90)
  4. ***
  5. ***    By CARL SASSENRATH, Ukiah, CA  (707)-462-4878
  6. ***
  7. ***    Free to Distribute amoung CDTV developers, but...
  8. ***    do not modify and pass it along without checking with me.
  9. ***
  10. ***    A simple program to stop a CD eject reset:  This would normally
  11. ***    be a part of a CDTV application.  This code creates an IOPort,
  12. ***    IORequest, and Change Interrupt, then posts an ADDCHANGEINT
  13. ***    to the device driver.  The CD File System will not reset on
  14. ***    an Eject (nor Insert for that matter) so long as some other
  15. ***    program is interested in knowing about the event.  As long
  16. ***    as your request is linked to the change interrupt list, the
  17. ***    FS will not reset the system.
  18. ***
  19. ***    The code below is not quite the same as you would put in a
  20. ***    CDTV application.  Here we must keep our structures active
  21. ***    even after the program completes and returns to the shell.
  22. ***    Note that we allocate the structures and leave them intact
  23. ***    after exiting.  Also note that the interrupt name and code
  24. ***    must be located in one of these allocated structures, not
  25. ***    within the program (as its memory will be freed on exit).
  26. ***    Your application would not have to do this because it would
  27. ***    stay present until it has completed, and at that time it
  28. ***    would free the structures.
  29. ***
  30. ***    There is other nastiness here because the IOPort might end
  31. ***    up containing an invalid task pointer.  This should not be a
  32. ***    problem so long as the SendIO never completes (which it
  33. ***    shouldn't because we don't do a REMCHANGEINT).  Your CDTV
  34. ***    application must do a REMCHANGEINT before it exits.
  35. ***
  36. ***********************************************************************/
  37.  
  38. #include <exec/types.h>
  39. #include <exec/interrupts.h>
  40. #include <exec/memory.h>
  41. #include <exec/io.h>
  42. #include "cd.h"
  43.  
  44. extern    void    *AllocMem();
  45. extern    struct    IOStdReq *CreateStdIO();
  46. extern    struct    MsgPort  *CreatePort();
  47. struct    IOStdReq *IORequest = NULL;
  48. struct    MsgPort  *IOPort = NULL;
  49. struct  sChgInt
  50. {
  51.     struct    Interrupt intr;
  52.     UWORD    IntCode;
  53.     char    Name[20];
  54. } *ChangeInt;
  55.  
  56. #define    MUST(expr)  if (!(expr)) Quit();
  57.  
  58. main(argc,argv)
  59.     int argc;
  60.     char *argv[];
  61. {
  62.     int track;
  63.  
  64.     if (argc < 2) track = 1;
  65.     else
  66.     {
  67.         track = atoi(argv[1]);
  68.         if (!track) track = 1;
  69.     }
  70.  
  71.     MUST(IOPort = CreatePort(0,0));
  72.     MUST(IORequest = CreateStdIO(IOPort));
  73.     MUST(ChangeInt = AllocMem(sizeof(*ChangeInt),MEMF_CLEAR));
  74.  
  75.     if (OpenDevice("cdtv.device",0,IORequest,0))
  76.         {printf("CDTV Device will not open\n");    Quit();}
  77.  
  78.     ChangeInt->IntCode = 0x4E75;    /* RTS instruction */
  79.     strcpy(ChangeInt->Name,"noreset.int");
  80.     ChangeInt->intr.is_Node.ln_Type = NT_INTERRUPT;
  81.     ChangeInt->intr.is_Node.ln_Name = ChangeInt->Name;
  82.     ChangeInt->intr.is_Code = &ChangeInt->IntCode;
  83.  
  84.     IORequest->io_Command = CD_ADDCHANGEINT;
  85.     IORequest->io_Data = (APTR)ChangeInt;
  86.     SendIO(IORequest);
  87.  
  88.     /* Exit, but DO NOT deallocate structures! */
  89. }
  90.  
  91. Quit()
  92. {
  93.     if (IORequest->io_Device) CloseDevice(IORequest);
  94.     if (IORequest)    DeleteStdIO(IORequest);
  95.     if (IOPort)    DeletePort(IOPort);
  96.     if (ChangeInt)    FreeMem(ChangeInt,sizeof(*ChangeInt));
  97. }
  98.  
  99.